package com.senven.api.service;

/**
 * @author LQP
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.senven.api.annotation.LogInfo;
import com.senven.api.commom.ResponsePage;
import com.senven.api.dao.OrganAffairMapper;
import com.senven.api.pojo.Department;
import com.senven.api.pojo.OrganAffair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrganAffairService {
    @Autowired
    private OrganAffairMapper organAffairMapper;

    /**
     *
     * 获取指定学生的社团事务
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganAffair> queryOrganAffairsByUid(String uid, int current, int size) {
        Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        wrapper.eq("uid",uid);
        IPage<OrganAffair> iPage = organAffairMapper.selectPage(page, wrapper);
        ResponsePage<OrganAffair> responsePage = new ResponsePage<OrganAffair>();
        responsePage.makePage(iPage);
        return responsePage;
    }

    /**
     *
     * 获取指定学生的指定活动
     * @return
     */
    public OrganAffair queryOrganAffairsByUidAndName(String uid, String name,int oid) {
        //Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        wrapper.eq("uid",uid).eq("logname",name).eq("oid",oid);
        OrganAffair organAffair = organAffairMapper.selectOne(wrapper);
        return organAffair;
    }

    /**
     *
     * 获取进行中的社团事务
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganAffair> queryOrganAffairsActive(int current, int size) {
        Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        wrapper.eq("status",1);
        IPage<OrganAffair> iPage = organAffairMapper.selectPage(page, wrapper);
        ResponsePage<OrganAffair> responsePage = new ResponsePage<OrganAffair>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     *
     * 获取社团事务
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganAffair> queryOrganAffairs(int current, int size){
        Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        IPage<OrganAffair> iPage = organAffairMapper.selectPage(page,null);
        ResponsePage<OrganAffair> responsePage= new ResponsePage<OrganAffair>();
        responsePage.makePage(iPage);
        return responsePage;
    }

    /**
     * ID获取社团事务
     * @param oid
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganAffair> queryOrganAffairList(int oid, int current, int size){
        Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();

        wrapper.eq("oid",oid);

        IPage<OrganAffair> iPage = organAffairMapper.selectPage(page,wrapper);

        ResponsePage<OrganAffair> responsePage= new ResponsePage<OrganAffair>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     * 名称查询社团事务
     * @param oid
     * @param name
     * @param current
     * @param size
     * @return
     */
    public ResponsePage<OrganAffair> queryOrganAffairList(int oid, String name, int current, int size){
        Page<OrganAffair> page = new Page<OrganAffair>(current, size);
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        if(oid !=0) {
            wrapper.eq("oid",oid);
        }
        wrapper.like("tips",name);
        IPage<OrganAffair> iPage = organAffairMapper.selectPage(page,wrapper);
        ResponsePage<OrganAffair> responsePage= new ResponsePage<OrganAffair>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     * 插入一条事务
     * @param organAffair
     * @return
     */
    @LogInfo(operateType = "社团事务",operateInfo = "添加社团事务")
    public int insertOrganAffair(OrganAffair organAffair){
        int result = organAffairMapper.insert(organAffair);
        return result;
    }

    /**
     * 删除一条事务
     * @param id
     * @return
     */
    @LogInfo(operateType = "社团事务",operateInfo = "删除社团事务")
    public int deleteOrganAffair(int id){
        int result = organAffairMapper.deleteById(id);
        return result;
    }

    /**
     * 更新一条事务
     * @param organAffair
     * @return
     */
    @LogInfo(operateType = "社团事务",operateInfo = "更新社团事务")
    public int updateOrganAffair(OrganAffair organAffair) {
        int result = organAffairMapper.updateById(organAffair);
        return result;
    }

    /**
     * 导出活动报名
     * @return
     */
    public List<OrganAffair> exportActivity(){
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        wrapper.ne("logname","加入社团");
        List<OrganAffair> result =  organAffairMapper.selectList(wrapper);
        return result;
    }

    /**
     * 导出社团报名
     * @return
     */
    public List<OrganAffair> exportOrgan(){
        QueryWrapper<OrganAffair> wrapper = new QueryWrapper<OrganAffair>();
        wrapper.eq("logname","加入社团");
        List<OrganAffair> result =  organAffairMapper.selectList(wrapper);
        return result;
    }

}
